package com.zzyl.mapper;

import com.github.pagehelper.Page;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.entity.Device;
import com.zzyl.vo.DeviceDataGraphVo;
import com.zzyl.vo.DeviceVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;


import java.time.LocalDateTime;
import java.util.List;

/**
 * @Description DeviceMapper
 * @Author Lwj
 * @Date 2024-09-11-15:16
 */
@Mapper
public interface DeviceMapper {
    /**
     * 查询是否存在相同的名字
     *
     * @param deviceName
     * @return
     */
    Long countByDeviceName(String deviceName);

    /**
     * 保存设备
     *
     * @param device
     */
    void insertSelective(Device device);

    /**
     * 分页查询
     *
     * @param devicePageQueryDto
     * @return
     */
    Page<DeviceVo> selectByPage(DevicePageQueryDto devicePageQueryDto);

    /**
     * 查询设备详细数据
     *
     * @param iotId
     * @return
     */
    DeviceVo selectByIotId(String iotId);


    int deleteByPrimaryKey(Long id);

    int insert(Device record);


    Device selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Device record);

    int updateByPrimaryKey(Device record);

    /**
     * 这是Mybatis Generator拓展插件生成的方法(请勿删除).
     * This method corresponds to the database table device
     *
     * @mbg.generated
     * @author hewei
     */
    int batchInsert(@Param("list") List<Device> list);

    /**
     * 按天获取每小时的心率统计数据
     *
     * @param iotId
     * @param functionId
     * @param minCreateTime
     * @param maxCreateTime
     * @return
     */
    List<DeviceDataGraphVo> queryDeviceDataListByDay(
            @Param("iotId") String iotId, @Param("functionId") String functionId,
            @Param("minCreateTime") LocalDateTime minCreateTime, @Param("maxCreateTime") LocalDateTime maxCreateTime);


    /**
     * 按周获取每天的心率统计数据
     *
     * @param iotId
     * @param functionId
     * @param minCreateTime
     * @param maxCreateTime
     * @return
     */
    List<DeviceDataGraphVo> queryDeviceDataListByWeek(
            @Param("iotId") String iotId, @Param("functionId") String functionId,
            @Param("minCreateTime") LocalDateTime minCreateTime, @Param("maxCreateTime") LocalDateTime maxCreateTime);


    List<Long> selectNursingIdsByIotIdWithElder(String iotId);

    List<Long> selectNursingIdsByIotIdWithBed(String iotId);

    /**
     * 删除设备
     * @param iotId
     */
    @Delete("delete from device where iot_id=#{iotId}")
    void deleteByIotId(String iotId);
}
